package com.flank.weather.logic.dao

import android.content.Context
import com.flank.weather.App
import com.flank.weather.logic.model.PlaceResponse
import com.google.gson.Gson

/**
 * Created by 2021/9/2
 * Email 270554501@qq.com
 * Author Flank
 *
 */
object PlaceDao {
    fun savePlace(place:PlaceResponse.Place){
        sharedPreferences().edit().putString("place",Gson().toJson(place)).commit()

    }
    fun getSavedPlace(): PlaceResponse.Place{
        val placeJson= sharedPreferences().getString("place","")
        return  Gson().fromJson(placeJson,PlaceResponse.Place::class.java)
    }
    fun isPlaceSaved()= sharedPreferences().contains("place")
    private fun sharedPreferences()=App.context.getSharedPreferences("sunny_weather",Context.MODE_PRIVATE)
}